﻿using System.Windows;
using System.Windows.Controls;
using Shrestha.Database;
using Shrestha.Trigraph;
using System;

namespace Shrestha.DataWizard
{
    /// <summary>
    /// Interaction logic for SelectTable.xaml
    /// </summary>
    public partial class SelectTable : Page
    {
        private DbManager dbMan;
        private DataSourceLoader dataSourceLoader;
        public SelectTable(DbManager dbMan, DataSourceLoader ds)
        {
            this.dbMan = dbMan;
            this.dataSourceLoader = ds;
            InitializeComponent();
            comboBoxSource.ItemsSource = dbMan.GetTables();
        }

        private void buttonNext_Click(object sender, RoutedEventArgs e)
        {
            if (null == comboBoxSource.SelectedValue || comboBoxSource.SelectedValue.ToString().Equals(""))
            {
                MessageBox.Show("Please select a table");
            }
            else
            {
                TriGraphResources.tableName = comboBoxSource.SelectedValue.ToString();
                SelectRows selectRows = new SelectRows(dbMan, dataSourceLoader);
                Uri nextUri = new Uri("SelectTable.xaml", UriKind.Relative);
                this.NavigationService.Navigate(selectRows);
            }
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            dataSourceLoader.DataLoaded = false;
            dataSourceLoader.Close();
        }
    }
}
